#!/usr/bin/env python3.8
# -*- encoding: utf-8 -*-
'''
@File    :   views.py
@Time    :   2021/10/09 10:34:21
@Author  :   windstarry 
@Version :   1.0
'''
#here put the import lib
#导入渲染模板函数
from flask import render_template, request,url_for,redirect
from app.main import main_bp
from flask_login import current_user
from datetime import datetime
from app.ext import db

@main_bp.route('/')
@main_bp.route('/index')
def index():
    return render_template('main/index.html')


@main_bp.before_app_request  # 在应用执行每一个请求之前执行的函数
def before_request():
    #用户登录时更新登录时间
    if current_user.is_authenticated:
        current_user.last_seen = datetime.utcnow()
        db.session.commit()
    #用户未认证时导航到认证页面
    if not current_user.is_anonymous and not current_user.confirmed and request.blueprint != 'auth':
        return redirect(url_for('auth.unconfirmed'))
    




